package com.yale.interceptor;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import java.util.Map;

/**
 * Created by yale on 2017/10/20.
 */
public class Interceptor extends AbstractInterceptor {

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        System.err.println("拦截器开始");
        //获取用户会话信息
        Map session = invocation.getInvocationContext().getSession();
        Object user = session.get("CURRENT_USER");
        if(null == user){
            System.err.println("拦截器结束1");
            //为空,返回到登陆页面
            return Action.LOGIN;
        }else{
            System.err.println("拦截器结束2");
            return invocation.invoke();//执行后面的action
        }
    }
}
